<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>ERP管理系统</title>
    <th:block th:include="include::header"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" id="roleId" name="roleId"
                   autocomplete="off" class="layui-input" th:value="${role.roleId}">



            <div class="layui-form-item" th:each="item:${submenus}" th:if="${item.powerCount!=0&&item.powerCount!=null}">
                <label class="layui-form-label">[[${item.name}]]:</label>
                <div class="layui-input-block">
                    <th:block th:if="${powers!=null}">
                        <th:block  th:each="item1:${powers}" th:if="${item1.parent==item.name}">
                            <input th:ids="${item1.powerId}" type="checkbox" th:name="${item1.type}" th:title="${item1.name}" checked="checked">
                        </th:block>
                    </th:block>

                    <th:block th:each="item2:${powers1}" th:if="${item2.parent==item.name}">
                        <input th:ids="${item2.powerId}" type="checkbox" th:name="${item2.type}" th:title="${item2.name}">
                    </th:block>
                </div>
            </div>

            <div class="layui-form-item">
                <button  class="layui-btn" lay-filter="update" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
</div>
<script >layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        $(".select").css("width","190px");


        //监听提交
        form.on('submit(update)',
            function(data) {
                var inputs=$("input[type='checkbox']");
                var ins=[];
                for (var i=0;i<inputs.length;i++) {
                    if(inputs[i].checked==true){
                        ins.push(inputs[i].getAttribute("ids"))
                    }
                }
                var ids=JSON.stringify(ins);
                $.post("/role/power",{
                    "ids":ids,
                    "roleId":data.field.roleId
                },function(res){
                    if(res.success){
                        layer.alert(res.msg, {
                                icon: 6
                            },
                            function() {
                                //关闭当前frame
                                xadmin.close();

                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });

                    }else{
                        layer.alert(res.msg, {icon:5});
                        return;
                    }
                });
                return false;
            });

    });</script>
</body>

</html>
